﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Subtext.Framework.Components;

namespace Subtext.Web.Admin.Feedback
{
    public class FeedbackState
    {
        public static FeedbackState GetUiState(FeedbackStatusFlag status)
        {
            //We've reduced multiple switch statements to one, 
            //that's good enough in my book.
            switch (status) 
            { 
                case FeedbackStatusFlag.Approved:
                    return new ApprovedFeedbackState();

                case FeedbackStatusFlag.NeedsModeration:
                    return new NeedsModerationState();

                case FeedbackStatusFlag.FlaggedAsSpam:
                    return new FlaggedAsSpamState();

                case FeedbackStatusFlag.Deleted:
                    return new DeletedState();

                default:
                    throw new InvalidOperationException("无效的评论状态'" + status + "'");
            }    
        }

        public string HeaderText = string.Empty ;
        public bool Approvable = true;
        public string ApproveText = "Approve";
        public bool Destroyable = false;
        public bool Deletable = true;
        public string DeleteToolTip = "删除选中的信息到回收站";
        public bool Spammable = true;
        public bool Emptyable = false;
        public string EmptyToolTip = "清空";
        public string NoCommentsHtml = "<em>评论列表为空</em>";
    }

    public class ApprovedFeedbackState : FeedbackState
    {
        public ApprovedFeedbackState()
        {
            HeaderText = "已审核的评论列表";
            Approvable = false;
        }
    }

    public class NeedsModerationState : FeedbackState
    {
        public NeedsModerationState() : base()
        {
            HeaderText = "待审核的评论";
            //NoCommentsHtml = "<em>待审核的评论为空</em>";
        }
    }

    public class FlaggedAsSpamState : FeedbackState
    {
        public FlaggedAsSpamState()
        {
            HeaderText = "已过滤的评论列表";
            DeleteToolTip = "删除选中的信息到回收站";
            Spammable = false;
            Emptyable = true;
            EmptyToolTip = "清空";
            //NoCommentsHtml = "<em>过滤的评论为空</em>";
        }
    }

    public class DeletedState : FeedbackState
    {
        public DeletedState()
        {
            HeaderText = "回收站的评论列表";
            Spammable = false;
            Deletable = false;
            DeleteToolTip = "删除选中的信息到回收站";
            Destroyable = true;
            Emptyable = true;
            EmptyToolTip = "清空所有垃圾信息";
            ApproveText = "还原";
            //NoCommentsHtml = "<em>回收站为空</em>";
        }
    }
}
